package com.itheima.service.imple.config;

import com.itheima.HelloSpring;
import com.itheima.dao.imple.UserDao;
import com.itheima.service.imple.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration//说明当前类是配置类 作用类似 applicationContext.xml
@ComponentScan//扫描项目中的所有bean类（添加了@Component
@EnableAspectJAutoProxy
@EnableWebMvc
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        HelloSpring h = context.getBean(HelloSpring.class);
        UserService userService = context.getBean(UserService.class);
        boolean flag = userService.login("张三", "123");
        if (flag) {
            System.out.println("登录成功");
        } else {
            System.out.println("登录失败");
        }
        UserDao userDao = context.getBean(UserDao.class);
        userDao.delete();
        userDao.insert();
        userDao.select();
        userDao.update();
//    public static void main(String[] args) {
//        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
//        HelloSpring h= context.getBean(HelloSpring.class);
//        h.setUserName("小明");
//        h.show();
//        UserService userService =  context.getBean(UserService.class);
//        boolean flag = userService.login("张三", "123");
//        if (flag) {
//            System.out.println("登录成功");
//        }else {
//            System.out.println("登录失败");
//        }
//        UserDao userDao = context.getBean(UserDao.class);
//        userDao.delete();
//        userDao.insert();
//        userDao.select();
//        userDao.update();
//    }
        @Bean
        public InternalResourceViewResolver viewResolver () {
            InternalResourceViewResolver internal = new InternalResourceViewResolver();
            internal.setPrefix("/WEB-INF/pagers/");
            internal.setSuffix(".jsp");
            return internal;
        }
    }
}